Skip to content

Allow sorting TOML table keys - #252

Open
orf wants to merge 2 commits into
macisamuele:masterfrom
orf:patch-1
Open

Allow sorting TOML table keys#252
orf wants to merge 2 commits into
macisamuele:masterfrom
orf:patch-1

Conversation

@orf

@orf orf commented Nov 8, 2024

Copy link
Copy Markdown

Quite often you want to keep the overall structure of a TOML file, but sort the keys within. For example, a Cargo.toml file:

[package]
name = "xyz"

[dependencies]
tokio = {version = "1.38.0", features = ["full"]}
clap = {version = "4.5.4", features = ["derive", "env"]}

Right now this will be re-formatted as

[dependencies]
clap = {version = "4.5.4", features = ["derive", "env"]}
tokio = {version = "1.38.0", features = ["full"]}

[package]
name = "xyz"

Which is annoying - I'd like to keep the [package] table at the top, but just sort the keys (dependencies, mostly) within:

[package]
name = "xyz"

[dependencies]
clap = {version = "4.5.4", features = ["derive", "env"]}
tokio = {version = "1.38.0", features = ["full"]}

This MR adds a flag to support this.

@thclark

thclark commented Jun 18, 2025

Copy link
Copy Markdown

Would love to see this merged! Usually there's only one you want at the top; typically [package] (rust) or [project] (for pyproject.toml) that by convention you want to have access to right at the top of the file.

@macisamuele
macisamuele enabled auto-merge June 24, 2025 13:38
@soraxas

soraxas commented Jul 1, 2026

Copy link
Copy Markdown

hello, will this get merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants